package com.fzhucc.modules.subject.rest;

import com.fzhucc.annotation.AnonymousAccess;
import com.fzhucc.annotation.Log;
import com.fzhucc.base.BaseEntity.Update;
import com.fzhucc.base.PageDTO;
import com.fzhucc.modules.subject.domain.dto.SubjectHighfieldsType2CreateDto;
import com.fzhucc.modules.subject.domain.dto.SubjectHighfieldsType2QueryCriteria;
import com.fzhucc.modules.subject.domain.dto.SubjectHighfieldsType2QueryDto;
import com.fzhucc.modules.subject.service.SubjectHighfieldsType2Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* @website https://fzhucc.com
* @author yyg
* @since 2022-09-26 00:00:00
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "HUCC：市级管理")
@RequestMapping("/api/city")
public class SubjectHighfieldsType2Controller {

    private final SubjectHighfieldsType2Service subjectHighfieldsType2Service;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@hu.check('city:list')")
    public void exportSubjectHighfieldsType2(HttpServletResponse response, SubjectHighfieldsType2QueryCriteria criteria) throws IOException {
        subjectHighfieldsType2Service.download(subjectHighfieldsType2Service.queryAll(criteria), response);
    }

    @GetMapping(value = "/queryCity")
    @Log("查询市级")
    @ApiOperation("查询市级")
    @AnonymousAccess
    public PageDTO<SubjectHighfieldsType2QueryDto> querySubjectHighfieldsType2(SubjectHighfieldsType2QueryCriteria criteria, Pageable pageable){
        return subjectHighfieldsType2Service.queryAll(criteria,pageable);
    }

    @PostMapping
    @Log("新增市级")
    @ApiOperation("新增市级")
    @PreAuthorize("@hu.check('city:add')")
    public SubjectHighfieldsType2QueryDto createSubjectHighfieldsType2(@Validated @RequestBody SubjectHighfieldsType2CreateDto resources){
        return subjectHighfieldsType2Service.create(resources);
    }

    @PutMapping
    @Log("修改市级")
    @ApiOperation("修改市级")
    @PreAuthorize("@hu.check('city:edit')")
    public void updateSubjectHighfieldsType2(@Validated @Update @RequestBody SubjectHighfieldsType2CreateDto resources){
        subjectHighfieldsType2Service.update(resources);
    }

    @DeleteMapping
    @Log("删除市级")
    @ApiOperation("删除市级")
    @PreAuthorize("@hu.check('city:del')")
    public void deleteSubjectHighfieldsType2(@RequestBody Integer[] ids) {
        subjectHighfieldsType2Service.deleteAll(ids);
    }
}